  
/** 
 * 时间对象的格式化; 
 */  
Date.prototype.format = function(format) {  
    /* 
     * eg:format="yyyy-MM-dd hh:mm:ss"; 
     */  
    var o = {  
        "M+" : this.getMonth() + 1, // month  
        "d+" : this.getDate(), // day  
        "h+" : this.getHours(), // hour  
        "m+" : this.getMinutes(), // minute  
        "s+" : this.getSeconds(), // second  
        "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter  
        "S" : this.getMilliseconds()  
        // millisecond  
    }  
  
    if (/(y+)/.test(format)) {  
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4  
                        - RegExp.$1.length));  
    }  
  
    for (var k in o) {  
        if (new RegExp("(" + k + ")").test(format)) {  
            format = format.replace(RegExp.$1, RegExp.$1.length == 1  
                            ? o[k]  
                            : ("00" + o[k]).substr(("" + o[k]).length));  
        }  
    }  
    return format;  
}


//ligerUI-grid option
function grid_ops(){
		return {      
		    enabledSort:false,
		    pageSize:15,
		    width: '100%',
		    height:'88%',
		    root:'rows',
		    record :'total',
		    pageParmName :'page',
		    pagesizeParmName :'pageSize',
		    method:'post',
		    dataAction:'server',
		    delayLoad :true,
		    pageSizeOptions:[10, 15, 20, 30, 40, 50],
		    onSuccess:function(data, grid){
		  	  if(data.hasError){
		  	    $.ligerDialog.error(data.message);
		  	    return false;
		  	  }
		    },
		    onAfterShowData:function(data){
		  	
		    }
	} ;
}

//开窗口
function openWindow(url, title, width, height)
{
    return $.ligerDialog.open({ width: width, height: height, title: title, url: url, buttons: [
    { text: '关闭', onclick: function ()
    {
    	hideCurrentWindow();
    } 
    }
    ], isResize: true
    });
}


function hideCurrentWindow(){
	 $.ligerDialog.close();
     $.ligerDialog.hide();
}

function init_validate(fromid){
	$.metadata.setType("attr", "validate");
	var f;
	if(fromid==undefined){
		f=$("form");
	}else{
		f=$("#"+formid);
	}
	var v = f.validate({
	  errorPlacement: function (lable, element)
	  {
	      lable.appendTo($(element).parent().next());
	  },
	  success: function (lable)
	  {
	      lable.ligerHideTip();
	      lable.remove();
	  },
	  submitHandler: function ()
	  {
	      $("form .l-text,.l-textarea").ligerHideTip();
	  }
	});
	return v;
}


$.ligerDefaults.Grid.formatters['datetime'] = function (datatime, column) {
    //num 当前的值
    //column 列信息
	if(Number(datatime)>0){
		  return  new Date(datatime).format("yyyy-MM-dd hh:mm:ss");
	}
};
$.ligerDefaults.Grid.formatters['datetime2'] = function (datatime, column) {
    //num 当前的值
    //column 列信息
	if(Number(datatime)>0){
		  return  new Date(datatime).format("yyyy-MM-dd hh:mm");
	}
};
window.dicData=0;
//加载字典表json
function loadDict(){
	$.getJSON("/dictionaryManager/all-data.json", function(json){
		window.dicData=json.data;
	});
}
function getDictMemo(type,code){
	remark="";
	if(0==window.dicData){
		loadDict();
	}
	if (!code&& code != 0){
		return remark;
	}
	codes=code.toString().split(","); //字符分割 
	for (i=0;i<codes.length ;i++ ) { 
		if(0!=i){
			memo+=",";
		}
		remark+=window.dicData[type.concat("|").concat(codes[i])];
	} 
	return remark;
}

$.ligerDefaults.Grid.formatters['fee'] = function (fee, column) {
    //num 当前的值
	if (!fee) return "0.00";
	return $.FormatMoney(fee);
};
$.ligerDefaults.Grid.formatters['is_update'] = function (code, column) {
	return getDictMemo(column.type,code);
}
$.ligerDefaults.Grid.formatters['is_realtime'] = function (code, column) {
	return getDictMemo(column.type,code);
}
$.ligerDefaults.Grid.formatters['catch_model'] = function (code, column) {
	return getDictMemo(column.type,code);
}
$.ligerDefaults.Grid.formatters['is_private'] = function (code, column) {
	return getDictMemo(column.type,code);
}
$.ligerDefaults.Grid.formatters['is_allow'] = function (code, column) {
	return getDictMemo(column.type,code);
}
$.ligerDefaults.Grid.formatters['flag'] = function (code, column) {
	return getDictMemo(column.type,code);
}


function getFormJson(frm) {
	var o='?';
	var a = $(frm).serializeArray();
	$.each(a, function () {
		if (this.name!== undefined) {
				o+=this.name+"="+this.value+"&";
		}
	});
	return o;
}
/*通用结束日期必须大于开始时间*/
/*传入start和end jQuery Dom对象 返回true或false*/
/* 如var end = $("#endTime")*/
function checkEndTime(start,end){  
    var startTime=start.val();  
    var startTimeVal=new Date(startTime.replace("-", "/").replace("-", "/"));  
    var endTime=end.val();  
    var endTimeVal=new Date(endTime.replace("-", "/").replace("-", "/")); 
	if(endTimeVal<startTimeVal){  
	    $.ligerDialog.error(end.attr("title")+"必须大于"+start.attr("title"));
        return false;  
    }  
    return true;  
}  

$(function(){
	loadDict();  
});
